package designPrinciple.openClosedPrinciple;

public class  OpenClosedPrinciple2{
    public static void main(String[] args) {
        //使用看看存在的问题
        GraphicEditor2 graphicEditor = new GraphicEditor2();
        graphicEditor.drawshape(new Rectangle2());
        graphicEditor.drawshape(new CirCle2());

        graphicEditor.drawshape(new Triangle2());
    }
}


//用于绘图的类
class GraphicEditor2 {
    //接收Shape2对象，然后根据type，来绘制不同的图形
    public void drawshape(Shape2 s) {
        s.draw();
    }

}

//Shape基类
abstract class Shape2 {
    int m_type;

    public abstract void draw();//抽象方法
}

class Rectangle2 extends Shape2 {
    Rectangle2() {
        super.m_type = 1;
    }

    @Override
    public void draw() {
        System.out.println("矩形");
    }
}

class CirCle2 extends Shape2 {
    CirCle2() {
        super.m_type = 2;
    }

    @Override
    public void draw() {
        System.out.println("圆形");
    }
}

//新增三角形
class Triangle2 extends Shape2 {
    Triangle2() {
        super.m_type = 3;
    }

    @Override
    public void draw() {
        System.out.println("三角形");
    }
}
